<?php
if(!defined('IN_MANU')){ die('[ERROR] You cannot load this page directly !!!'); }

/**
 * BaseController class
 * 
 * @package    application
 * 
 */
 
Abstract Class BaseController 
{
    /*
     * Registry object
     */
    protected $registry;
    
    /**
     * Contructor
     */
    function __construct($registry) 
    {
    	$this->registry = $registry;
    }
    
    /**
     * All controllers contain an index method
     */
    abstract function index();
    
    /*
     * @description:	Get basic info table to show in default
     * 
     */
    public function getEntityTable($atts = array(), $rows = array(), $type, $grant = false)
    {
    	$tem = $this->registry->template;
    
    	$tags['manuTableHeader'] = $tem->getTableHeader($atts);
    	$tags['manuTableContent'] = '';
    	
    	$alterRow = false;
    	foreach ($rows as $row) {
    		$tags['manuTableContent'] .= $tem->getTableRow($atts, $row, $alterRow, $type, $grant);
    		$alterRow = !$alterRow;
    	}
    
    	$tags['path'] = MANU_ROOT_PATH . $type;
    	
    	$res = $tem->getModule('table', $tags);
    
    	return $res;
    }
    
    /*
     * @description:	Get general info table of one object
     * 
     */
    public function getGeneralTable($name, array $atts = array(), $type, $table = null)
    {
    	$man = $this->registry->db->get($type . 'Manager');
    	
    	$res = '<div id="title">General</div><hr>';
    	$tbl = '<table id="general-table">';
    	if ($type == 'privilege')
    		$rows = $man->getBasicInfo($name, $table);
    	else 
    		$rows = $man->getBasicInfo($name);
    	foreach ($atts as $key) {
    		$val = $rows[0]->get(strtoupper($key));
    		$tbl .= '<tr><td class="first-column">' . $key . '</td><td class="second-column">' . $val . '</td></tr>';
    	}
    	$tbl .= '</table>';
    	
    	$res .= $tbl;
    	
    	return $res;
    }
}

?>
